#include "mqttfx.h"
#include <QJsonObject>
#include <QJsonDocument>
#include <QDebug>
#include <QJsonArray>
MqttFx::MqttFx()
{

}

MqttFx::~MqttFx()
{

}

QMQTT::Client* MqttFx::InitClient()
{
    client->setHostName("183.230.40.39");
    client->setPort(6002);
    client->setUsername("606300");
    QString pwd = "597522";
    client->setPassword(pwd.toLatin1());
    client->setClientId("1087719017");
    client->setVersion(QMQTT::V3_1_1);
    return client;
}

void MqttFx::SenOneNet(QMQTT::Client *client, QString data)
{
    QJsonObject json;
    json.insert("tem",25.5);
    QString json_str = QJsonDocument(json).toJson(QJsonDocument::Compact);
    QMQTT::Message mes(136,"humidity",json_str.toUtf8());
    QMQTT::Message mes2(12,"$dp",data.toLatin1());
    bool ok = client->publish(mes);
    bool ok_1 = client->publish(mes2);
    if(ok && ok_1   )
    {
        qDebug() << "ok";
    }else
    {
        qDebug() << "Error";
    }
}

void MqttFx::receivedOne(QMQTT::Client *client)
{

}
